package pro1.前缀和.t303;

/**
 * @Author xingyu Xue
 * @Date 2024/2/14 20:31
 */
public class 数组检索 {
    public static void main(String[] args) {

    }

}
class NumArray {
    //构造前缀和数组
    int[] preSum;
    public NumArray(int[] nums) {
        int n= nums.length;
        preSum = new int[n+1]; //初始化数组
        for (int i = 0; i < n; i++) {
            preSum[i+1] = preSum[i] + nums[i];
        }

    }

    public int sumRange(int left, int right) {
        return preSum[right + 1] - preSum[left];
    }
}
